home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / NNUTL101.ZIP / NNSIM2 / NNHEBBLN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-31  |  2.3 KB  |  58 lines

  1. /*-----------------------------------------------------------------------*
  2.  * Greg Stevens                                                   6/24/93*
  3.  *                              NNHEBBLN.C                               *
  4.  *                                             [file 6 in a series of 6] *
  5.  *                                                                       *
  6.  * This file contains the functions for calculating the error and weight *
  7.  * changes for the Hebb rule for unsupervised learning.  Defined         *
  8.  * in this file are EPSILON, the weight change increment/coefficient,    *
  9.  * and function that updates the weights [UpDateWeightandThresh()].  It  *
  10.  * also contains code for a function called GetDerivs(), but this is to  *
  11.  * be used in the function UpDateWeightsandDerivs(), not by a main       *
  12.  * program.                                                              *
  13.  *                                                                       *
  14.  *-----------------------------------------------------------------------*/
  15. #include "nnloadin.c"
  16.  
  17. #define EPSILON 0.01        /* constant incrementation for weight change */
  18.  
  19. /* Function Prototype */
  20. NNETtype UpDateWeightandThresh( NNETtype oldn );
  21.  
  22. /* Function Definition */
  23. NNETtype UpDateWeightandThresh( NNETtype oldn )
  24. {
  25.    NNETtype n;
  26.    int u,v;
  27.    int BIG = 0;
  28.  
  29.    n = oldn;
  30.  
  31.    for (u=0; (u<OUTPUT_LAYER_SIZE); ++u )
  32.      {
  33.        if (n.unit[1][u].state>0.0)                 /* increment weights of */
  34.          {                                          /* connex. btw. any co- */
  35.             for (v=0; (v<INPUT_LAYER_SIZE); ++v )   /* active nodes.        */
  36.               {
  37.                 if (n.unit[0][v].state>0.0)
  38.                   n.unit[1][u].weights[v] += EPSILON;
  39.                 if (n.unit[1][u].weights[v]>10.0)
  40.                   BIG = 1;
  41.               }
  42.          }
  43.      }
  44.  
  45.    if (BIG==1)                                      /* if weights grew too  */
  46.      {                                              /* much, scale all down */
  47.        for (u=0; (u<OUTPUT_LAYER_SIZE); ++u )
  48.          {
  49.             for (v=0; (v<INPUT_LAYER_SIZE); ++v )
  50.               {
  51.                  n.unit[1][u].weights[v] = n.unit[1][u].weights[v] / 2.0;
  52.               }
  53.          }
  54.      }
  55.  
  56.    return( n );
  57. }
  58.